package cn.codergege.demo.config

import org.springframework.util.StringUtils
import org.springframework.web.servlet.LocaleResolver
import java.util.*
import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse

class MyLocaleResolver: LocaleResolver {
    override fun resolveLocale(request: HttpServletRequest): Locale {
        var locale = Locale.getDefault()
        val l = request.getParameter("l")
        if(!StringUtils.isEmpty(l)) {
            val ls = l.split("_")
            locale = Locale(ls[0], ls[1])
        }
        return locale
    }
    override fun setLocale(request: HttpServletRequest, response: HttpServletResponse?, locale: Locale?) {
        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    }
}
